package com.hotel.controller;

import com.hotel.pojo.Goods;
import com.hotel.service.GoodsService;
import com.hotel.utils.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * User: JiangMingda
 * File: GoodsController
 * Time: 2022/8/17 17:18
 * Description:
 */
@Controller
@RequestMapping("/goods")
public class GoodsController {

    // 装配goodsService
    @Autowired
    private GoodsService goodsService;

    // 查询商品
    @GetMapping("/goods")
    @ResponseBody
    public ResultInfo selectGoods(String goodsName, int page, int size){
        return goodsService.selectGoods(goodsName, page, size);
    }

    // 删除商品
    @DeleteMapping("/goods/{goodsId}")
    @ResponseBody
    public ResultInfo DeleteGoodsByGoodsName(@PathVariable("goodsId") Integer goodsId){
        System.out.println(goodsId);
        return goodsService.DeleteGoodsByGoodsId(goodsId);
    }

    // 修改商品信息
    @PutMapping("/goods")
    @ResponseBody
    public ResultInfo updateGoodsByGoodsName(Goods goods){
        return goodsService.updateGoodsByGoodsName(goods);
    }

    // 新增商品
    @PostMapping("/goods")
    @ResponseBody
    public ResultInfo insertGoods(Goods goods){
        return goodsService.insertGoods(goods);
    }

    // 商品使用情况分析
    @GetMapping("/goodsVisual")
    @ResponseBody
    public ResultInfo goodsVisual(){
        return goodsService.goodsVisual();
    }

}
